<!DOCTYPE>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>扩展运行符</title>

    <script>
        function myFunction(a, b) {
            return a + b;
        }
        var data = [1, 4];
        var result = myFunction.apply(null, data);
        console.log(result); // 5
    </script>

    <script src="js/traceur.js"></script>
    <script src="js/bootstrap.js"></script>
    <script type="module">
        function myFunction(a, b) {
            return a + b;
        }
        let data = [1, 6];
        let result = myFunction(...data);
        console.log(result); // 7
    </script>

    <script type="module">
        let array1 = [2, 3, 4];
        let array2 = [1, ...array1, 5, 6, 7];
        console.log(array2); //1, 2, 3, 4, 5, 6, 7
    </script>

    <!--将一个数组的值赋值到另一个数组的末尾-->
    <script type="module">
        var array1 = [2, 3, 4];
        var array2 = [1];
        Array.prototype.push.apply(array2, array1);
        console.log(array2); // 1, 2, 3, 4

        array2.push(...array1);
        console.log(array2); //1, 2, 3, 4

        //用几个数组扩展
        let array11 = [1];
        let array12 = [2];
        let array13 = [...array11, ...array12, ...[3, 4]];
        let array14 = [5];
        function myFunction(a, b, c, d, e) {
            return a+b+c+d+e;
        }
        let result = myFunction(...array13, ...array14);
        console.log(result); // 15

    </script>


    <!--多余的参数-->
    <script  type="module">
        function  myFunciton1(a, b) {
            var args = Array.prototype.slice.call(arguments, myFunciton1.length);
            console.log(args);
        }
        myFunciton1(1, 2, 3, 4, 5); // 3, 4, 5

        function myFuction2(a, b, ...args) {
            console.log(args);
        }
        myFuction2(1, 2, 3, 4, 5);
    </script>

</head>
</html>